//
//  DHDiagnosisViewController.m
//  DHKuaiYi
//
//  Created by xiaohuihui on 2016/11/13.
//  Copyright © 2016年 30-陈辉华. All rights reserved.
//

#import "DHDiagnosisViewController.h"
#import "DHSubtitleView.h"
#import "DHWeatherView.h"
#import "DHDoctorView.h"
#import "Masonry.h"
#import "SDCycleScrollView.h"
#import "NetworkTool.h"
#import "DHChooseDiseaseViewController.h"
#import "DHDoctorCollectionViewCell.h"

@interface DHDiagnosisViewController ()<SDCycleScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
/* 天气 */
@property (strong, nonatomic) DHWeatherView *weatherView;
/* 图片轮播 */
@property (strong, nonatomic) SDCycleScrollView *cycleScrollView;
/* 字幕栏 */
@property (strong, nonatomic) DHSubtitleView *subtitleView;
/* 诊断 */
@property (strong, nonatomic) DHDoctorView *doctorView;
/* 图片数组 */
@property (strong, nonatomic) NSArray *arr;
/* 分类名称数组 */
@property (strong, nonatomic) NSArray *arr2;

@end

@implementation DHDiagnosisViewController

-(void)viewDidLoad{
    [super viewDidLoad];
    [self getloopData];
}

/*------------------<##>------------------*/
#pragma mark - 推出预约控制器（测试用）
- (void)xhhSetupNavigationItems {
    
    [super xhhSetupNavigationItems];
    
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithTitle:@"预约" style:UIBarButtonItemStylePlain target:self action:@selector(pushChooseDiseaseVC)];
    
    self.navigationItem.rightBarButtonItem = rightBtn;
}

#pragma mark - 推出预约控制器（测试用）
- (void)pushChooseDiseaseVC {
    
    DHChooseDiseaseViewController *chooseDiseaseVC = [[DHChooseDiseaseViewController alloc] init];
    
    chooseDiseaseVC.hidesBottomBarWhenPushed = YES;
    
    [self.navigationController pushViewController: chooseDiseaseVC animated:YES];
    
}
/*------------------<##>------------------*/

/**
 初始化
 */
- (void)xhhSetupSubviews{
    [super xhhSetupSubviews];
  //实例化
  DHWeatherView *weatherView = [[DHWeatherView alloc] init];
    [self.view addSubview:weatherView];
    
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:nil];
    [self.view addSubview:cycleScrollView];
    
    DHSubtitleView *subtitleView = [[DHSubtitleView alloc] init];
    [self.view addSubview:subtitleView];
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize=CGSizeMake(123, 92);
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.minimumLineSpacing = 0;
    DHDoctorView *doctorView = [[DHDoctorView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    //代理设置
    doctorView.delegate=self;
    doctorView.dataSource=self;
    //注册item类型 这里使用系统的类型
    [doctorView registerClass:[DHDoctorCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    [self.view addSubview:doctorView];
   
    //自动布局
    //天气
    [weatherView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_topLayoutGuideBottom);
        make.left.right.mas_equalTo(self.view);
        make.height.mas_equalTo(70.5);
    }];
    //图片轮播
    [cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weatherView.mas_bottom);
        make.left.right.mas_equalTo(self.view);
        make.height.mas_equalTo(250);
    }];
    //字幕栏轮播
    [subtitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(cycleScrollView.mas_bottom);
        make.left.right.mas_equalTo(self.view);
        make.height.mas_equalTo(44.5);
    }];
    //诊断
    [doctorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(subtitleView.mas_bottom);
        make.left.right.mas_equalTo(self.view);
        make.bottom.equalTo(self.mas_bottomLayoutGuideTop);
    }];
    
    
    // 记录控件
    self.cycleScrollView = cycleScrollView;
    self.subtitleView = subtitleView;
    self.weatherView = weatherView;
    self.doctorView = doctorView;

}

/**
 加载网络图片轮播数据
 */
- (void)getloopData {
        //首页轮播图接口
    NSString *url = @"http://iosapi.itcast.cn/doctor/banners.json.php";
  NSDictionary *parameters = @{@"page_size":@10,@"page":@1};
    
    [[NetworkTool sharedTool] POSTWithURLStr:url parameters:parameters success:^(id responseObject) {
        NSDictionary *dic = responseObject[@"data"];
        NSArray *banners = dic[@"banners"];
        NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:banners.count];
        //遍历数组
        for (NSDictionary *dict in banners) {
            
            [arrayM addObject:dict[@"banner_img_url"]];
            
        }
       //回到主线程,刷新UI
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            self.cycleScrollView.imageURLStringsGroup = arrayM;
        }];
        
    } failed:^(NSError *error) {
        NSLog(@"%@",error);
    }];
    
    
    //图片数组
    self.arr = [NSArray arrayWithObjects:@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg",@"5.jpg",@"6.jpg", nil];
//    self.array=@{@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg",@"5.jpg",@"6.jpg"};
    
    self.arr2 =[NSArray arrayWithObjects:@"肿瘤", @"心血管",@"神经科",@"血液科",@"骨科",@"公益活动",nil];
}
#pragma mark -UICollectionViewDataSource


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 6;
}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    DHDoctorCollectionViewCell * cell  = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.imageView.image = [UIImage imageNamed:self.arr[indexPath.item]];
    cell.label.text = self.arr2[indexPath.row];
   
    return cell;
}






#pragma mark -UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    DHChooseDiseaseViewController *chooseDiseaseVC = [[DHChooseDiseaseViewController alloc] init];
    
    chooseDiseaseVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController: chooseDiseaseVC animated:YES];

    
}


@end






















